package Others;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JOptionPane;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

import TableAdditions.main;

public class BillAdd {
	
	
	public String customerCode="RG";
	public int personelId=2;
	public String billDate="09-09-2012";
	public float specialPrice=(float) 1.2;
	public int amount= 10;
	public float billCash=(float)200;
	
	public int productId=4;
	public float billCost=(float) specialPrice*amount;
	public float billCredit=(float) billCost-billCash;	
	
	
	
	public BillAdd() {
		String billDate2 = billDate.replaceAll("(\\d+)-(\\d+)-(\\d+)", "$3-$2-$1");
		// TODO Auto-generated constructor stub
		
		String insert="INSERT INTO bill (customer_code,personel_id,bill_date,bill_cost," +
        		"bill_cash,bill_credit,special_price,product_id,bill_amount)";
String values="VALUES ('"+customerCode+"','"+personelId+"','"+billDate2+"','"+billCost+"','"+billCash+"','"+billCredit+"','"+specialPrice+"','"+productId+"','"+amount+"')";


System.out.println("Ready to execute sql");
 	Connection con = null;
    Statement st = null;
    ResultSet rs = null;

    String url = "jdbc:mysql://localhost:3306/mydb";
    String user = "root";
    String password = "qweasdzxc";

    try {
        con = (Connection) DriverManager.getConnection(url, user, password);
        st = (Statement) con.createStatement();
        //st.executeUpdate("INSERT INTO job " + "VALUES (1, 'deneme')");
     //   st.executeUpdate("UPDATE customer SET customer_phone='0554755' WHERE customer_name='rehber';");
     //   st.executeUpdate(insert + values);

        //addTa(newRow[0]);
        //st.executeUpdate("DELETE FROM job");
        rs=st.executeQuery("SELECT * from vehicle ORDER BY vehicle_id");
        int i=0;
        while(rs.next())
        {
        	i++;
        	System.out.println(rs.getString(3));
        }
        int messageType = JOptionPane.PLAIN_MESSAGE;
      
        JOptionPane.showMessageDialog(null,"Kayıt Alındı", "Uyarı!!", messageType);
        con.close();
    } catch (SQLException ex) {
        Logger lgr = Logger.getLogger(main.class.getName());
        lgr.log(Level.SEVERE, ex.getMessage(), ex);

    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
            if (st != null) {
                st.close();
            }
            if (con != null) {
                con.close();
            }
            
            
        } catch (SQLException ex) {
            Logger lgr = Logger.getLogger(main.class.getName());
            lgr.log(Level.WARNING, ex.getMessage(), ex);
        }
    }
 
	}
	public void Insert(){
		
	}
	public static void main(String[] args) {
	       
        new BillAdd();
	}

}
